
#include "../src/catlog.h"

#include <time.h>
#include <stdio.h>

/*
 * #include <stdio.h>
void catlog_write_to_stderr(uint8_t * buffer,uint32_t size) {
    fprintf(stderr,"%s", buffer);
}*/

int main() {

    catlog_init();
    LOG_INFO("<---------------------  time used  ---------------------------->");
#if 1
    clock_t start,stop;
    start = clock();
    for(int i = 0; i < 10; ++i){
        LOG_INFO("this is %d,%f,%s",i,3.14159,"hello world");
    }
    stop = clock();
    LOG_INFO("MAX push out cnts %d",catlog_push_out_cnts);
    LOG_INFO("time used %d ms",(int)(1e3f * (stop-start)/CLOCKS_PER_SEC));
#endif
    LOG_INFO("<---------------------  base function test  ---------------------------->");
    LOG_INFO("this is INFO message: %d", 1);
    LOG_DEBUG("this is DEBUG message: %f %.4f", 1.0,2.14231423);
    LOG_WARNING("this is WARNING message: %f", 2);
    LOG_ERROR("this is ERROR message: 0x%x", 0xff);
    LOG_FETAL("this is FETAL message: %d %d", 2, 4);

    for (int i = 0; i <= 20; i++) {
        LOG_INFO_EVERY(5, "this will log info every 5 times(current i = %d)", i);
        LOG_DEBUG_FIRST(3, "this will log debug only the first 3 times(current i = %d)", i);
    }
    int k = 3;
    LOG_INFO_IF(k++ < 4, "this tells: k>5? k=%d", k);

    LOG_INFO("<---------------------  number output test  ---------------------------->");
    LOG_INFO("%d", 1234);	                    //		"1234"
    LOG_DEBUG("%6d,%3d%%", -200, 5);	            //"  -200,  5%"
    LOG_ERROR("%-6u", 100);			            //"100   "
    LOG_WARNING("%ld", 12345678);		            //"12345678"
    LOG_INFO("%llu", 0x100000000);              //	"4294967296"	<XF_USE_LLI>
    LOG_DEBUG("%lld", -1LL);		                //	"-1"			<XF_USE_LLI>
    LOG_WARNING("%04x", 0xA3);			            //"00a3"
    LOG_ERROR("%08lX", 0x123ABC);		        //"00123ABC"
    LOG_INFO("%016b", 0x550F);		            //"0101010100001111"
    LOG_WARNING("%*d", 6, 100);	                //		"   100"
    LOG_INFO("%s", "String");	                //	"String"
    LOG_INFO("%5s", "abc");		                //	"  abc"
    LOG_INFO("%-5s", "abc");		            //	"abc  "
    LOG_INFO("%-5s", "abcdefg");	            //	"abcdefg"
    LOG_INFO("%-5.5s", "abcdefg");              //	"abcde"
    LOG_INFO("%-.5s", "abcdefg");               //	"abcde"
    LOG_INFO("%-5.5s", "abc");		            //"abc  "
    LOG_INFO("%c", 'a');			            //	"a"
    LOG_INFO("%12f", 10.0);			            //"   10.000000"	<XF_USE_FP>
    LOG_INFO("%.4E", 123.45678);		        //"1.2346E+02"	<XF_USE_FP>

    catlog_deinit();
    /* do NOT use LOG_INFO again!*/
    printf("output counts:%d\n",catlog_push_out_cnts);
    return 0;
}
